package com.alertdroid2;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyCustomBaseAdapter extends BaseAdapter {
	private static ArrayList<MemoClass> memoList;

	private LayoutInflater mInflater;

	public MyCustomBaseAdapter(Context context, ArrayList<MemoClass> results) {
		memoList = results;
		mInflater = LayoutInflater.from(context);
	}

	public int getCount() {
		return memoList.size();
	}

	public Object getItem(int position) {
		return memoList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.custom_row_view, null);
			holder = new ViewHolder();
			holder.txtName = (TextView) convertView.findViewById(R.id.name);
			holder.txtPlace = (TextView) convertView
					.findViewById(R.id.place);
			holder.txtTime = (TextView) convertView.findViewById(R.id.time);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.txtName.setText(memoList.get(position).getNama());
		holder.txtPlace.setText(memoList.get(position).getPlace());
		holder.txtTime.setText(memoList.get(position).getWaktu().format("%d-%m-%Y %H:%M"));

		return convertView;
	}

	static class ViewHolder {
		TextView txtName;
		TextView txtPlace;
		TextView txtTime;
	}

}
